package BookStore.view;

import BookStore.dao.Vip_dDao;
import BookStore.model.Vip_d;
import java.awt.EventQueue;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout.Alignment;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.LayoutStyle.ComponentPlacement;

public class del_vip extends JFrame {

    private JPanel contentPane;
    private JTextField textField;


    /**
     * Launch the application.
     */
    public static void xe() {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    del_vip frame = new del_vip();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public del_vip() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);

        JLabel lblNewLabel = new JLabel("删除会员");
        lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 25));
        lblNewLabel.setForeground(Color.RED);

        JLabel lblNewLabel_1 = new JLabel("请输入要删除的会员编号");

        JLabel lblNewLabel_2 = new JLabel("编号：");

        textField = new JTextField();
        textField.setColumns(10);

        JButton btnNewButton = new JButton("删除");

        JButton btnNewButton_1 = new JButton("返回");
        GroupLayout gl_contentPane = new GroupLayout(contentPane);
        gl_contentPane.setHorizontalGroup(
                gl_contentPane.createParallelGroup(Alignment.LEADING)
                        .addGroup(gl_contentPane.createSequentialGroup()
                                .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
                                        .addGroup(gl_contentPane.createSequentialGroup()
                                                .addGap(148)
                                                .addComponent(lblNewLabel))
                                        .addGroup(gl_contentPane.createSequentialGroup()
                                                .addGap(83)
                                                .addComponent(lblNewLabel_2)
                                                .addGap(18)
                                                .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
                                                        .addComponent(textField, GroupLayout.PREFERRED_SIZE, 154, GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(lblNewLabel_1)))
                                        .addGroup(gl_contentPane.createSequentialGroup()
                                                .addGap(103)
                                                .addComponent(btnNewButton)
                                                .addGap(97)
                                                .addComponent(btnNewButton_1)))
                                .addContainerGap(110, Short.MAX_VALUE))
        );
        gl_contentPane.setVerticalGroup(
                gl_contentPane.createParallelGroup(Alignment.LEADING)
                        .addGroup(gl_contentPane.createSequentialGroup()
                                .addComponent(lblNewLabel)
                                .addPreferredGap(ComponentPlacement.RELATED)
                                .addComponent(lblNewLabel_1)
                                .addGap(18)
                                .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
                                        .addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                        .addComponent(lblNewLabel_2))
                                .addPreferredGap(ComponentPlacement.RELATED, 74, Short.MAX_VALUE)
                                .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
                                        .addComponent(btnNewButton)
                                        .addComponent(btnNewButton_1))
                                .addGap(65))
        );
        contentPane.setLayout(gl_contentPane);

        btnNewButton_1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                setVisible(false);
                new A_VIP().re();
            }
        });

        btnNewButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String t1 = textField.getText();

                if (t1.length() > 0) {

                   Vip_d vip_d = new Vip_d(t1);

                    try {
                        new Vip_dDao(vip_d).delete();

                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "编号不能为空");
                }
            }
        });
    }
}